CC := g++
CFLAGS := -std=c++11 -Wall -Wextra -pthread

# 目标可执行文件
TARGET := tracer_example

# 源文件
SRCS := main.cpp

# 头文件路径
INCLUDES := -I..

# 目标文件
OBJS := $(SRCS:.cpp=.o)

# 默认目标
all: $(TARGET)

# 编译规则
$(TARGET): $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^

# 编译源文件
%.o: %.cpp
	$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# 禁用跟踪的编译选项
disable_trace: CFLAGS += -DTRACE_DISABLED
disable_trace: clean $(TARGET)

# 清理生成的文件
clean:
	rm -f $(OBJS) $(TARGET) trace_result.json

# 运行示例
run: $(TARGET)
	./$(TARGET)

# 查看跟踪结果
view: run
	@echo "Trace file generated: trace_result.json"
	@echo "Please open chrome://tracing in your browser and load the file to view results"

.PHONY: all clean run view disable_trace
